<template>
  <j-modal-no-footer
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row class="j-modal-title-row" type="flex">
            <a-col>
              <input  type = "hidden" v-model="queryParam.technologyId"/>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button @click="handleAddNew" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->


      <!-- table区域-begin -->
      <!--:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange">


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a @click="showBOM(record)">BOM</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="删除会将关联的BOM一并删除，确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
          </a-popconfirm>
          <!--<a-dropdown>-->
            <!--<a class="ant-dropdown-link">更多 <a-icon type="down"/></a>-->
            <!--<a-menu slot="overlay">-->
              <!--<a-menu-item>-->
                <!--<a @click="handleDetail(record)">详情</a>-->
              <!--</a-menu-item>-->
              <!--<a-menu-item>-->
                <!--<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
                  <!--<a>删除</a>-->
                <!--</a-popconfirm>-->
              <!--</a-menu-item>-->
            <!--</a-menu>-->
          <!--</a-dropdown>-->
        </span>

        </a-table>
      </div>

      <mes-technology-procedure-modal ref="modalForm" @ok="modalFormOk"></mes-technology-procedure-modal>
      <MesTechnologyProcedureDOM ref="mesTechnologyProcedureDOM"></MesTechnologyProcedureDOM>
    </a-card>
  </j-modal-no-footer>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  import {getAction} from '@/api/manage'
  import MesTechnologyProcedureModal from './modules/MesTechnologyProcedureModal'
  import MesTechnologyProcedureDOM from './MesTechnologyProcedureDOM'

  export default {
    name: 'MesTechnologyProcedureList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      MesTechnologyProcedureModal,MesTechnologyProcedureDOM
    },
    data() {
      return {
        title: '工艺工序',
        width: 896,
        visible: false,
        disableSubmit: false,

        technologyId: '',
        lineId: '',

        description: '工艺工序表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '工位',
            align: 'center',
            dataIndex: 'stationId_dictText'
          },
          {
            title: '标准节拍',
            align: 'center',
            dataIndex: 'standardBeat'
          },
          {
            title: '工位属性',
            align: 'center',
            dataIndex: 'stationAttribute_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/mes/mesTechnologyProcedure/list',
          delete: '/mes/mesTechnologyProcedure/delete',
          deleteBatch: '/mes/mesTechnologyProcedure/deleteBatch',
          exportXlsUrl: '/mes/mesTechnologyProcedure/exportXls',
          importExcelUrl: 'mes/mesTechnologyProcedure/importExcel'

        },
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      this.getSuperFieldList()
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      //自定义方法----start
      showBOM(record){
        this.$refs.mesTechnologyProcedureDOM.show(record.id,record.stationAttribute,record.checkType);
      },
      handleAddNew() {
        this.$refs.modalForm.add(this.technologyId, this.lineId)
      },
      handleCancel() {
        this.close()
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      show(technologyId, lineId) {
        this.visible = true
        this.technologyId = technologyId
        this.lineId = lineId

        //搜索
        this.ipagination.current = 1;
        this.queryParam.technologyId = technologyId;
        this.loadData(1);
      },
      //自定义方法------end
      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        const params = this.getQueryParams();//查询条件
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
        })
      },
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({
          type: 'string',
          value: 'stationId',
          text: '工位id',
          dictCode: 'mes_base_factory,factory_name,id'
        })
        fieldList.push({ type: 'string', value: 'standardBeat', text: '标准节拍', dictCode: '' })
        fieldList.push({ type: 'string', value: 'technologyId', text: '工艺id', dictCode: '' })
        fieldList.push({ type: 'string', value: 'stationAttribute', text: '工位属性', dictCode: 'station_attribute' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>